/**
 * 修改用户数据
 */

import { NextResponse } from 'next/server';
import pool from '@/lib/db'
import { IUser } from '@/type/user';
//添加用户
export async function POST(request: Request) {
  try {
    // 从连接池中获取连接
    const connection = await pool.getConnection()
    const { newName, newAge, newDepartmentId } = await request.json();
    
    const [rows, result] = await connection.query('INSERT INTO user (name, age, department_id) VALUES (?, ?, ?)', [newName, newAge, newDepartmentId]);

    connection.release();
    
    console.log('Rows: ', rows)
    return NextResponse.json({ data: rows }, { status: 200 })
  } catch (error) {
    console.error('Error:', error)
    return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 })
  }
}